package com.dbsun.service.st;

import com.dbsun.common.ServerResponse;
import com.dbsun.entity.system.Page;
import com.dbsun.entity.system.PageData;
import com.dbsun.mapper.st.CommentsMapper;
import com.dbsun.service.BaseService;
import com.dbsun.util.Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CommentsService extends BaseService {
    @Autowired
    private CommentsMapper CommentsMapper;

    public List<PageData> getPageCommentsList(Page page) {
        return CommentsMapper.getPageCommentsList(page);
    }

    public ServerResponse<List<PageData>> getCommentsList(PageData pd) {
        if (Tools.isObjEmpty("111")) {
            return ServerResponse.badArgument();
        }
        return ServerResponse.createBySuccess(CommentsMapper.getCommentsList(pd));
    }

    public List<PageData> getCommentsList2(PageData pd) {

        return CommentsMapper.getCommentsList(pd);
    }

    @Transactional
    public ServerResponse<String> addComments(PageData pd) {
        int rowCount = CommentsMapper.addComments(pd);
        if (rowCount > 0) {
            return ServerResponse.createBySuccessMessage("添加成功");
        }
        return ServerResponse.createByErrorMessage("添加失败");
    }

    @Transactional
    public ServerResponse<String> updateCommentsByid(PageData pd) {
        if (Tools.isObjEmpty(pd.get("id"))) {
            return ServerResponse.createByErrorMessage("修改参数错误");
        }
        int rowCount = CommentsMapper.updateCommentsByid(pd);
        if (rowCount > 0) {
            return ServerResponse.createBySuccessMessage("修改成功");
        }
        return ServerResponse.createByErrorMessage("修改失败");
    }

    public ServerResponse<PageData> getCommentsByColumn(PageData pd) {
        if (Tools.isObjEmpty(pd.get("id"))) {
            return ServerResponse.createByErrorMessage("获取数据参数错误");
        }
        return ServerResponse.createBySuccess(CommentsMapper.getCommentsByColumn(pd));
    }

    public PageData getCommentsByColumn2(PageData pd) {

        return CommentsMapper.getCommentsByColumn(pd);
    }

    public ServerResponse<String> deleteCommentsByColumn(PageData pd) {
        if (Tools.isObjEmpty(pd.get("id"))) {
            return ServerResponse.createByErrorMessage("删除参数错误");
        }
        int rowCount = CommentsMapper.deleteCommentsByColumn(pd);
        if (rowCount > 0) {
            return ServerResponse.createBySuccessMessage("删除成功");
        }
        return ServerResponse.createByErrorMessage("删除失败");
    }
}
